﻿using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
    [Route(("souvenir/order"))]
    public class OrderController : BaseController
    {
        private readonly IOrderService _orderService;

        public OrderController(IOrderService orderService)
        {
            _orderService = orderService;
        }
        
        [HttpPost("addOrder")]
        public async Task<IActionResult> AddOrder([FromBody] Order order)
        {
            return SUCCESS(await _orderService.InsertOrderAsync(order) > 0);
        }

        [HttpPut("updateOrder")]
        public async Task<IActionResult> UpdateOrder([FromBody] Order order)
        {
            return SUCCESS(await _orderService.UpdateOrderAsync(order) > 0);
        }
        
        [HttpDelete("deleteOrder/{orderId}")]
        public async Task<IActionResult> DeleteOrder(int orderId)
        {
            return SUCCESS(await _orderService.DeleteOrderAsync(orderId) > 0);
        }
        
        [HttpPost("getOrderWithPage")]
        public async Task<IActionResult> GetOrderWithPage([FromBody] OrderQueryDto orderQueryDto)
        {
            return SUCCESS(await _orderService.SelectOrderWithPageAsync(orderQueryDto));
        }
        
        [HttpGet("getOrderById/{orderId}")]
        public async Task<IActionResult> GetOrderById(int orderId)
        {
            return SUCCESS(await _orderService.SelectOrderAsyncById(orderId));
        }
        
        [HttpGet("getSalesPerYear")]
        public async Task<IActionResult> GetSalesPerYear([FromQuery] DateTime year)
        {
            return SUCCESS(await _orderService.SelectSalesPerYearAsync(year));
        }
        
        [HttpGet("getSalesPerMonth")]
        public async Task<IActionResult> GetSalesPerMonth([FromQuery] DateTime month)
        {
            return SUCCESS(await _orderService.SelectSalesPerMonthAsync(month));
        }
        
        [HttpGet("getSalesWithCategory")]
        public async Task<IActionResult> GetSalesWithCategory()
        {
            return SUCCESS(await _orderService.SelectSalesWithCategoryAsync());
        }
    }
}